<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>MapVGL</title>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  <style>
    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
    }
    #map_container {
      width: 100%;
      height: 100%;
      margin: 0;
    }
  </style>
  <script src="//api.map.baidu.com/api?v=2.0&ak=baiduKey"></script>
  <script src="https://code.bdstatic.com/npm/mapvgl@1.0.0-beta.119/dist/mapvgl.min.js"></script>
</head>
<body>
<div id="map_container"></div>
<script>
  /* global BMap */

  /* global mapv */

  /* global mapvgl */

  /* global initMap */

  var map;

  // 百度地图API功能
  var map = new BMap.Map('map_container', {
    enableMapClick: false
  }); // 创建Map实例

  /*
  map.setMapStyle({
      style: 'midnight'
  });
  */

  map.centerAndZoom(new BMap.Point(106.563777, 29.578285), 15); // 初始化地图,设置中心点坐标和地图级别
  map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放

  var view = new mapvgl.View({
    effects: [new mapvgl.BloomEffect({
      threshold: 0.8
    })],
    mapType: 'bmap',
    map: map
  });

  fetch('../../data/chongqing.json').then(function (rs) {
    return rs.json();
  }).then(function (rs) {
    var data = rs;
    var polygons = [];
    var len = data.length;
    for (var i = 0; i < len; i++) {
      var line = data[i];
      var polygon = [];
      var pt = [line[1] * 512, line[2] * 512];
      for (var j = 3; j < line.length; j += 2) {
        pt[0] += line[j] / 100 / 2;
        pt[1] += line[j + 1] / 100 / 2;
        polygon.push([pt[0], pt[1]]);
      }

      polygons.push({
        geometry: {
          type: 'Polygon',
          coordinates: [polygon]
        },
        properties: {
          height: line[0] / 2
        }
      });
    }

    var shaperLayer = new mapvgl.ShapeLayer({
      texture: '../../img/light.jpg',
      // texture: 'images/heatmap.png',
      blend: 'lighter',
      color: [0.8, 0.8, 0.1],
      opacity: 1.0
    });
    view.addLayer(shaperLayer);
    shaperLayer.setData(polygons);

  });
</script>
</body>
</html>
